package com.oracle.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oracle.compents.PageResult;
import com.oracle.mapper.PhSeverMapper;
import com.oracle.pojo.PhSever;
import com.oracle.pojo.PhSeverExample;
import com.oracle.pojo.PhSeverExample.Criteria;
import com.oracle.service.SeverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class SeverServiceImpl implements SeverService {

	@Autowired
	private PhSeverMapper severMapper;

	/**
	 * 查询全部
	 */
	@Override
	public List<PhSever> findAll() {
		return severMapper.selecPhyExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Page<PhSever> page=   (Page<PhSever>) severMapper.selecPhyExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(PhSever sever) {
		severMapper.insert(sever);
	}


	/**
	 * 修改
	 */
	@Override
	public void update(PhSever sever){
		severMapper.updateByPrimaryKey(sever);
	}

	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public PhSever findOne(Integer id){
		return severMapper.selecPhyPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Integer[] ids) {
		for(Integer id:ids){
			severMapper.deleteByPrimaryKey(id);
		}
	}


		@Override
	public PageResult findPage(PhSever sever, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);

		PhSeverExample example=new PhSeverExample();
		Criteria criteria = example.createCriteria();

		if(sever!=null){
						if(sever.getServename()!=null && sever.getServename().length()>0){
				criteria.andServenameLike("%"+sever.getServename()+"%");
			}			if(sever.getRemark()!=null && sever.getRemark().length()>0){
				criteria.andRemarkLike("%"+sever.getRemark()+"%");
			}
		}

		Page<PhSever> page= (Page<PhSever>)severMapper.selecPhyExample(example);
		return new PageResult(page.getTotal(), page.getResult());
	}

}
